/**
 * @file SdpFactory.h
 * @author Derek Liu (yjkhtddx@sina.com)
 * @brief 
 * @version 0.1
 * @date 2024-1-13
 * 
 * @copyright Copyright Sci-Tech Laboratories (c) 2024
 * 
 */

// #pragma once
#ifndef __SdpFactory_h__
#define __SdpFactory_h__

#include "SdpOptions.h"
#include <string>
#include <vector>
#include <regex>

namespace STL
{
    int getSdpValue(std::string &sdp, std::string key, std::string &value, int offset = 0);
    std::vector<std::string> split(std::string str, std::string pattern);

    std::string getCommandString(GB_SDP_Command cmd);
    GB_SDP_Command getCommandEnum(std::string cmd);

    std::string getTcpTypeStr(GB_SDP_TcpType type);
    GB_SDP_TcpType getTcpTypeEnum(std::string type);

    std::string getProtoStr(GB_SDP_Proto proto);
    GB_SDP_Proto getProtoEnum(std::string proto);

    // std::string getIpType(GB_SDP_IpType type);
    // GB_SDP_IpType getIpType(std::string type);

    /**
         * @brief 生成ssrc（详见国标SDP要求）
         * 
         * @param cmd 命令值
         * @param deviceId4to8 String 设备编码4到8位 符合正则表达式 ^\d{5}$ [340(20000)002000000002]
         * @return std::string SDP字符串
         */
    std::string genSSRC(GB_SDP_Command cmd, std::string deviceId4to8 = "00000");
    std::string genSSRC(GBSdpOptions &options);
    unsigned int getSsrcFromStr(std::string ssrc);
    std::string getSsrcFromUint(unsigned int ssrc);

    class GBSdp
    {
    public:
        virtual std::string genSdp(GBSdpOptions &options) = 0;
    };
    class GBSdpTcpRecv : GBSdp
    {
    public:
        std::string genSdp(GBSdpOptions &options) override;
    };
    class GBSdpTcpSend : GBSdp
    {
    public:
        std::string genSdp(GBSdpOptions &options) override;
    };
    class GBSdpUdpRecv : GBSdp
    {
    public:
        std::string genSdp(GBSdpOptions &options) override;
    };
    class GBSdpUdpSend : GBSdp
    {
    public:
        std::string genSdp(GBSdpOptions &options) override;
    };
    class GBSdpFactory : GBSdp
    {
    public:
        static GBSdpOptions parseSdp(std::string sdp);
        std::string genSdp(GBSdpOptions &options) override;
    };
} // namespace STL

#endif //__SdpFactory_h__